package com.tao.auto.batchtao.home.account;

import com.tao.auto.batchtao.base.PhoneMessageCode;
import com.tao.auto.batchtao.base.accout.BaseAccount;
import com.tao.auto.batchtao.utils.RandomName;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Random;

/**
 * @author GLNC-taowenchen
 */
@Component
public class HomeRegisterAccountImpl implements BaseAccount<HomeAccount> {
    PhoneMessageCode<String> deafultPhoneMessageCode;

    public HomeRegisterAccountImpl(PhoneMessageCode<String> deafultPhoneMessageCode) {
        this.deafultPhoneMessageCode = deafultPhoneMessageCode;
    }

    @Override
    public HomeAccount account() {
        String phone = deafultPhoneMessageCode.phone();
        if (StringUtils.isBlank(phone)) {
            return null;
        }
        HomeAccount homeAccount = new HomeAccount();
        homeAccount.setAccount(phone);
        homeAccount.setNickname(RandomName.randomName(true, 3));
        homeAccount.setPassword(RandomName.randomPassword());

        int i = random.nextInt(arrays.size());
        homeAccount.setSpread(arrays.get(i).getId());
        homeAccount.setSign(arrays.get(i).getPhone());
        return homeAccount;
    }

    public List<MainUser> arrays = Arrays.asList(new MainUser("18107965722", "1042"), new MainUser("18107067457", "1043"));

    Random random = new Random();

    public static class MainUser {
        String phone;
        String id;

        public String getPhone() {
            return phone;
        }

        public void setPhone(String phone) {
            this.phone = phone;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public MainUser(String phone, String id) {


            this.phone = phone;
            this.id = id;
        }
    }

}
